using Google.ProtocolBuffers;
using micromsg;
using MicroMsg.Common.Utils;
using MicroMsg.Storage;
using System;
using System.Collections.Generic;
using System.Linq;
namespace MicroMsg.Manager
{
	public class OpLogMgr
	{
		public enum FunctionID : uint
		{
			QQMailPushNotify = 1u,
			DisableFindMeByQQ,
			DisableRecommendMeToQQFriends,
			NeedVerify,
			RecvOfflineQQMsg,
			DisableRecommendQQFriendsToMe,
			DisableRecommendMobileFirendsToMe,
			DisableFindMeByMobile,
			DisableAutoAddFriendWhenReply,
			DisablePushMsgDetail,
			BottleMsgNotify,
			DisplayWeixinOnLine,
			MediaNote,
			BottleInChat,
			GMail,
			TXWeibo,
			DisableUploadMContact,
			RECFBFriend,
			Reader,
			ReaderTXNews,
			ReaderTXWeibo,
			TXWeiboIcon,
			MM_FUNCTIONSWITCH_MEISHI_CARD_OPEN,
			MM_FUNCTIONSWITCH_ALBUM_NOT_FOR_STRANGER,
			MM_FUNCTIONSWITCH_USERNAME_SEARCH_CLOSE,
			MM_FUNCTIONSWITCH_NEWSAPP_TXNEWS_CLOSE
		}
		public enum FunctionValue : uint
		{
			enable = 1u,
			disable
		}
		private const string TAG = "OpLogMgr";
		public static bool smethod_0(OpLog opLog_0)
		{
			return opLog_0 != null && (opLog_0.nCmdId >= 0 && opLog_0.nCmdId < 48) && (opLog_0.bytesCmdBuf != null && opLog_0.bytesCmdBuf.Length > 0) && StorageMgr.oplog.method_3(opLog_0);
		}
		public static bool addList(List<OpLog> opList)
		{
			return opList != null && StorageMgr.oplog.addList(opList);
		}
		public static int count()
		{
			return StorageMgr.oplog.count();
		}
		public static void clear(int nMaxOplogID)
		{
			StorageMgr.oplog.clear(nMaxOplogID);
		}
		public static CmdList getCmdItemList()
		{
			List<OpLog> list = StorageMgr.oplog.getList();
			CmdList.Builder builder = new CmdList.Builder();
			if (list != null && list.get_Count() > 0)
			{
				using (List<OpLog>.Enumerator enumerator = list.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						OpLog current = enumerator.get_Current();
						SKBuiltinBuffer_t cmdBuf = Util.toSKBuffer(current.bytesCmdBuf);
						CmdItem cmdItem = CmdItem.CreateBuilder().SetCmdId(current.nCmdId).SetCmdBuf(cmdBuf).Build();
						if (cmdItem != null)
						{
							builder.ListList.Add(cmdItem);
						}
					}
				}
				return builder.SetCount((uint)builder.ListList.get_Count()).Build();
			}
			return builder.SetCount(0u).Build();
		}
		public static int getMaxOplogID()
		{
			List<OpLog> list = StorageMgr.oplog.getList();
			if (list != null && list.get_Count() > 0)
			{
				return Enumerable.Max<OpLog>(list, (OpLog opLog_0) => opLog_0.nID);
			}
			return 0;
		}
		public static void dumpData()
		{
			List<OpLog> list = StorageMgr.oplog.getList();
			if (list == null)
			{
				return;
			}
			Log.smethod_5("OpLogMgr", "************ oplist  count = " + list.get_Count());
			using (List<OpLog>.Enumerator enumerator = list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					OpLog current = enumerator.get_Current();
					object object_ = CmdItemHelper.toCmdObject(current);
					Log.smethod_5("OpLogMgr", object_.debugString());
				}
			}
			Log.smethod_5("OpLogMgr", "************ ************");
		}
		public static bool opFunctionSwitch(OpLogMgr.FunctionID functionID_0, bool enable)
		{
			FunctionSwitch.Builder builder = FunctionSwitch.CreateBuilder();
			builder.FunctionId = (uint)functionID_0;
			builder.SwitchValue = (enable ? 1u : 2u);
			return OpLogMgr.smethod_0(new OpLog(23, builder.Build().ToByteArray()));
		}
		public static bool opUploadSelfHeadimg(uint BitFlag, Account account_0, byte[] imgBuf)
		{
			if (BitFlag != 0u && account_0 != null)
			{
				ModUserInfo.Builder builder = ModUserInfo.CreateBuilder();
				builder.BitFlag = BitFlag;
				builder.UserName = Util.toSKString(account_0.strUsrName);
				builder.NickName = Util.toSKString("");
				builder.BindUin = 0u;
				builder.BindEmail = Util.toSKString("");
				builder.BindMobile = Util.toSKString("");
				builder.Status = 0u;
				builder.ImgLen = (uint)imgBuf.Length;
				builder.ImgBuf = ByteString.CopyFrom(imgBuf);
				return OpLogMgr.smethod_0(new OpLog(1, builder.Build().ToByteArray()));
			}
			return false;
		}
		public static bool opModUserInfo(uint BitFlag, Account account_0)
		{
			if (BitFlag != 0u && account_0 != null)
			{
				ModUserInfo.Builder builder = ModUserInfo.CreateBuilder();
				builder.BitFlag = BitFlag;
				builder.UserName = Util.toSKString(account_0.strUsrName);
				builder.NickName = Util.toSKString("");
				builder.BindUin = 0u;
				builder.BindEmail = Util.toSKString("");
				builder.BindMobile = Util.toSKString("");
				builder.Status = 0u;
				builder.ImgLen = 0u;
				if ((BitFlag & 1u) != 0u)
				{
					builder.UserName = Util.toSKString(account_0.strUsrName);
				}
				if ((BitFlag & 2u) != 0u)
				{
					builder.NickName = Util.toSKString(account_0.strNickName);
				}
				if ((BitFlag & 4u) != 0u)
				{
					builder.BindUin = account_0.nUin;
				}
				if ((BitFlag & 8u) != 0u)
				{
					builder.BindEmail = Util.toSKString(account_0.strBindEmail);
				}
				if ((BitFlag & 16u) != 0u)
				{
					builder.BindMobile = Util.toSKString(account_0.strBindMobile);
				}
				if ((BitFlag & 32u) != 0u)
				{
					builder.Status = account_0.nStatus;
				}
				if ((BitFlag & 128u) != 0u)
				{
					builder.PersonalCard = account_0.nPersonalCard;
					builder.Sex = account_0.nSex;
					builder.Signature = ((account_0.strSignature == null) ? "" : account_0.strSignature);
					builder.Province = ((account_0.strProvince == null) ? "" : account_0.strProvince);
					builder.City = ((account_0.strCity == null) ? "" : account_0.strCity);
				}
				if ((BitFlag & 2048u) != 0u)
				{
					builder.PluginFlag = account_0.nPluginFlag;
				}
				return OpLogMgr.smethod_0(new OpLog(1, builder.Build().ToByteArray()));
			}
			return false;
		}
		public static bool OpModChatRoomTopic(string chatRoomName, string chatRoomTopic)
		{
			ModChatRoomTopic.Builder builder = ModChatRoomTopic.CreateBuilder();
			builder.ChatRoomName = Util.toSKString(chatRoomName);
			builder.ChatRoomTopic = Util.toSKString(chatRoomTopic);
			return OpLogMgr.smethod_0(new OpLog(27, builder.Build().ToByteArray()));
		}
		public static bool OpModChatRoomNotify(string chatRoomName, uint status)
		{
			ModChatRoomNotify.Builder builder = ModChatRoomNotify.CreateBuilder();
			builder.ChatRoomName = Util.toSKString(chatRoomName);
			builder.Status = status;
			return OpLogMgr.smethod_0(new OpLog(20, builder.Build().ToByteArray()));
		}
		public static bool OpDelChatContact(string userName)
		{
			DelChatContact.Builder builder = DelChatContact.CreateBuilder();
			builder.UserName = Util.toSKString(userName);
			return OpLogMgr.smethod_0(new OpLog(7, builder.Build().ToByteArray()));
		}
		public static bool OpDelContact(string userName)
		{
			DelContact.Builder builder = DelContact.CreateBuilder();
			builder.UserName = Util.toSKString(userName);
			return OpLogMgr.smethod_0(new OpLog(4, builder.Build().ToByteArray()));
		}
		public static bool OpQuitChatRoom(string chatRoomName)
		{
			QuitChatRoom.Builder builder = QuitChatRoom.CreateBuilder();
			builder.UserName = Util.toSKString(AccountMgr.getCurAccount().strUsrName);
			builder.ChatRoomName = Util.toSKString(chatRoomName);
			return OpLogMgr.smethod_0(new OpLog(16, builder.Build().ToByteArray()));
		}
		public static bool OpModContact(Contact contact_0, uint bitMask)
		{
			ModContact.Builder builder = ModContact.CreateBuilder();
			builder.UserName = Util.toSKString(contact_0.strUsrName);
			builder.NickName = Util.toSKString(contact_0.strNickName);
			builder.PYInitial = Util.toSKString(contact_0.strPYInitial);
			builder.QuanPin = Util.toSKString(contact_0.strQuanPin);
			builder.Sex = contact_0.nSex;
			builder.ImgBuf = Util.toSKBuffer("");
			builder.BitMask = bitMask;
			builder.BitVal = contact_0.nFlags;
			builder.ImgFlag = contact_0.nImgFlag;
			builder.Remark = Util.toSKString(contact_0.strRemark);
			builder.RemarkPYInitial = Util.toSKString(contact_0.strRemarkPYInitial);
			builder.RemarkQuanPin = Util.toSKString(contact_0.strRemarkQuanPin);
			builder.ContactType = contact_0.nContactType;
			builder.RoomInfoCount = 0u;
			builder.DomainList = Util.toSKString(contact_0.strDomainList);
			builder.ChatRoomNotify = contact_0.nChatRoomNotify;
			builder.AddContactScene = contact_0.nAddContactScene;
			builder.Province = Util.NullAsNil(contact_0.strProvince);
			builder.City = Util.NullAsNil(contact_0.strCity);
			builder.Signature = Util.NullAsNil(contact_0.strSignature);
			builder.PersonalCard = contact_0.nPersonalCard;
			builder.HasWeiXinHdHeadImg = contact_0.nHasWeiXinHdHeadImg;
			builder.VerifyFlag = contact_0.nVerifyFlag;
			builder.VerifyInfo = Util.NullAsNil(contact_0.strVerifyInfo);
			return OpLogMgr.smethod_0(new OpLog(2, builder.Build().ToByteArray()));
		}
		public static bool OpModBrandSetting(string username, uint BrandFlag)
		{
			ModBrandSetting.Builder builder = ModBrandSetting.CreateBuilder();
			builder.UserName = username;
			builder.BrandFlag = BrandFlag;
			return OpLogMgr.smethod_0(new OpLog(47, builder.Build().ToByteArray()));
		}
		public static bool OpModMsgStatus(int msgSvrId, string fromUserName, string toUserName, uint status)
		{
			ModMsgStatus.Builder builder = ModMsgStatus.CreateBuilder();
			builder.MsgId = msgSvrId;
			builder.FromUserName = Util.toSKString(fromUserName);
			builder.ToUserName = Util.toSKString(toUserName);
			builder.Status = status;
			return OpLogMgr.smethod_0(new OpLog(6, builder.Build().ToByteArray()));
		}
		public static bool OplogAddKVStat(int int_0, string value)
		{
			KVStatOpLog.Builder builder = KVStatOpLog.CreateBuilder();
			KVStatItem.Builder builder2 = KVStatItem.CreateBuilder();
			builder2.Key = (uint)int_0;
			builder2.Value = value;
			builder.AddList(builder2.Build());
			builder.Count = (uint)builder.ListCount;
			return OpLogMgr.smethod_0(new OpLog(36, builder.Build().ToByteArray()));
		}
		public static bool OplogAddKVStat(List<KVStat> items)
		{
			if (items != null && items.get_Count() > 0)
			{
				KVStatOpLog.Builder builder = KVStatOpLog.CreateBuilder();
				for (int i = 0; i < items.get_Count(); i++)
				{
					KVStatItem.Builder builder2 = KVStatItem.CreateBuilder();
					builder2.Key = (uint)items.get_Item(i).enKVStatKey_0;
					builder2.Value = items.get_Item(i).value;
					builder.AddList(builder2.Build());
				}
				builder.Count = (uint)builder.ListCount;
				return OpLogMgr.smethod_0(new OpLog(36, builder.Build().ToByteArray()));
			}
			return false;
		}
		public static bool OpDeleteBottle(string string_0, int throwBackType = 0)
		{
			DeleteBottle.Builder builder = DeleteBottle.CreateBuilder();
			builder.BottleId = string_0;
			builder.ThrowBackType = throwBackType;
			return OpLogMgr.smethod_0(new OpLog(32, builder.Build().ToByteArray()));
		}
		public static bool OpSendPsmStat(PSMSTAT_KEY psmstat_KEY_0, string tipID)
		{
			PSMStat.Builder builder = PSMStat.CreateBuilder();
			builder.MType = (uint)psmstat_KEY_0;
			builder.AType = tipID;
			return OpLogMgr.smethod_0(new OpLog(26, builder.Build().ToByteArray()));
		}
	}
}
